package com.zmzncs.lmtc.module.promotion.controller;


import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.DateTimeUtil;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.promotion.dao.MonthRulePullDao;
import com.zmzncs.lmtc.module.promotion.pojo.month_rule_fee_scale.MonthRuleFeeScaleDTO;
import com.zmzncs.lmtc.module.promotion.pojo.month_rule_fee_scale.MonthRuleFeeScaleVO;
import com.zmzncs.lmtc.module.promotion.pojo.month_rule_pull.MonthRulePullDTO;
import com.zmzncs.lmtc.module.promotion.service.MonthRuleFeeScaleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 任建波
 * @since 2020-08-12
 */
@Api(tags = "月租规则的收费标准")
@RestController
@RequestMapping("/promotion/month-rule-paytype")
@Validated
public class MonthRulePaytypeController {

    @Autowired
    MonthRuleFeeScaleService monthRuleFeeScaleService;
    @Autowired
    MonthRulePullDao monthRulePullDao;

    @ApiOperation(value = "根据停车场id查询月租支付规则")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name="parkId", value="停车场id", required = true),
            @ApiImplicitParam(paramType="query", name="cardType", value="卡类型（1：月卡，2：时长卡 ，4：充值，100：白天卡，101：夜间卡）", required = true),
    })
    @GetMapping(value = "getMonthRulePaytypeByParkId")
    public Rest<List<MonthRuleFeeScaleVO>> getMonthRulePaytypeByParkId(@RequestParam Long parkId, Integer cardType) {
        List<MonthRuleFeeScaleDTO> monthRuleFeeScaleDTOList = monthRuleFeeScaleService.getMonthRuleFeeScaleByParkId(parkId, cardType);
        List<MonthRuleFeeScaleVO> monthRuleFeeScaleVOList = JsonUtil.listTransform(monthRuleFeeScaleDTOList, MonthRuleFeeScaleVO.class);

        //  该停车场还没有开启月租服务
        if(monthRuleFeeScaleVOList.size() == 0){
            return RestUtil.success("该停车场还没有开启月租服务");
        } else {
            return RestUtil.success(monthRuleFeeScaleVOList);
        }
    }

}

